<?php
namespace app\manage\controller;

use think\Controller;
use think\Request;
use think\Validate;
use think\Db;
use Config;

/**报修
 * Class UnitBuilding
 * @package app\manage\controller
 */
class Repair extends Controller{

    /**
     * 报修显示
     * @return \think\response\Json
     */
    public function repairList(){
        $model=new \app\manage\model\Repair();
        $date=$model->repairList();
        returnJson(200,"成功",$date)->send();die;
    }

//$where['u_id']=create_id($data['token']);
    /**
     * 报修添加
     * @return \think\response\Json
     */
    public function repairAdd(){
        $model=new \app\manage\model\Repair();
        $input = input();
        $date=$model->recordAdd($input);
        returnJson(200,"成功")->send();die;
    }
    /**
     * 编辑维修记录
     */
    public function repairOne()
    {
        $model=new \app\manage\model\Repair();
        $data = input();
        if(Request::instance()->isGet()) {
            $h_id = trim($data['m_id']);
            $data = $model->repairOne($h_id);
            //判断后台有没有设置单元楼栋数
            if ($data == 2) {
                returnJson(-411, "报修数据不存在")->send();
                die;
            } else {
                returnJson(200, "成功", $data)->send();
                die;
            }
        }else{
            $data = $model->recordEditor($data);
            //判断后台有没有设置单元楼栋数
            if ($data) {
                returnJson(200, "成功")->send();
                die;
            } else {
                returnJson(-411, "失败")->send();
                die;
            }
        }
    }
    /**
     * 报修记录删除
     * @return \think\response\Json
     */
    public function repairDel(){
        $model=new \app\manage\model\Repair();
        $input = input();
        $date=$model->recordDel($input);
        if($date){
            returnJson(200,"成功")->send();die;
        }else{
            returnJson(-444,"失败")->send();die;
        }
    }

    /**
     * 报修提交
     * @return \think\response\Json
     */
    public function repairConfirm(){
        $model=new \app\manage\model\Repair();
        $input = input();
        $date=$model->repairConfirm($input);
        if($date){
            returnJson(200,"成功")->send();die;
        }else{
            returnJson(-444,"失败")->send();die;
        }
    }

    /**
     * 报修查看
     * @return \think\response\Json
     */
    public function repairWithdrawal(){
        $model=new \app\manage\model\Repair();
        $input = input();

        $date=$model->PayRentWithdrawal($input);
        if($date){
            returnJson(200,"成功",$date)->send();die;
        }else{
            returnJson(-444,"失败")->send();die;
        }
    }
    /**
     * 指派
     * @return \think\response\Json
     */
    public function repairAssign(){
        $model=new \app\manage\model\Repair();
        $input = input();
        $date=$model->assign($input);
        if($date){
            returnJson(200,"成功")->send();die;
        }else{
            returnJson(-444,"失败")->send();die;
        }
    }
    /**
     * 维修完成
     * @return \think\response\Json
     */
    public function maintenanceCompleted(){
        $model=new \app\manage\model\Repair();
        $input = input();
        $date=$model->maintenanceCompleted($input);
        if($date){
            returnJson(200,"成功")->send();die;
        }else{
            returnJson(-444,"失败")->send();die;
        }
    }

}